package com.goodlearning.gloriamobile.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.goodlearning.gloriamobile.R;
import com.goodlearning.gloriamobile.commons.Constants;
import com.goodlearning.gloriamobile.commons.Utils;

/**
 * 더보기 Activity
 * 
 * @author rapty54
 * 
 */
public class More extends BaseActivity {

	String[] text = { "로그아웃","학교시설위치", "글로리아 사이버 캠퍼스", "북카페", "취업지원센터", "항공학교",
			"호텔학교", "요리학교", "미용학교" };

	Button showEachText;

	int[] resourceId = {R.id.more_logout_button, R.id.more_Facil_location,
			R.id.more_gloria_cyber_location, R.id.more_bookcafe,
			R.id.more_Employment_support_center, R.id.more_air_school,
			R.id.more_hotel_school, R.id.more_cooking_school,
			R.id.more_Beauty_School };
	
	int [] resourceIdxTv={R.id.map_textView_bt,R.id.gloria_textView_bt
			,R.id.bookcafeWeb_textView_bt,R.id.Employment_textView_bt
			,R.id.air_textView_bt,R.id.hotel_textView_bt
			,R.id.cooking_textView_bt,R.id.Beauty_textView_bt};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.more_body_layout);
		init();
	}

	public void init() {
		baseTitleLeftBtn.setVisibility(View.INVISIBLE);
		baseTitleRightBtn.setVisibility(View.INVISIBLE);
		baseTitleTv.setText("글로리아교육재단");
		textViewInit(resourceIdxTv);
		for (int i = 0; i < resourceId.length; i++) {

			final int resource = resourceId[i];
			String show = text[i];

			showEachText = (Button) findViewById(resource);
			showEachText.setText(show);
			showEachText.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {

					switch (resource) {
					
					case R.id.more_logout_button:
						Utils.log("============0=========");
						allClearActivityAndReturnBack();
						break;
					case R.id.more_Facil_location:
						Utils.log("============1=========");
						Utils.changeActivity(More.this, MoreGloriaMapPosition.class);
						break;
					case R.id.more_gloria_cyber_location:
						Utils.log("============2=========");
						Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cyber.gloriahrd.com/"));
						startActivity(intent);
						break;
					case R.id.more_bookcafe:
						Utils.log("============3=========");
						Intent book = new Intent(Intent.ACTION_VIEW, Uri.parse("http://book.gloriahrd.com/"));
						startActivity(book);
						break;
					case R.id.more_Employment_support_center:
						Utils.log("============4=========");
						Intent job = new Intent(Intent.ACTION_VIEW, Uri.parse("http://job.kac.ac.kr/"));
						startActivity(job);
						break;
					case R.id.more_air_school:
						Utils.log("============5=========");
						Intent kac = new Intent(Intent.ACTION_VIEW, Uri.parse("http://kac.ac.kr/"));
						startActivity(kac);
						break;
					case R.id.more_hotel_school:
						Utils.log("============6=========");
						Intent hotel = new Intent(Intent.ACTION_VIEW, Uri.parse("http://hotel.ac.kr/"));
						startActivity(hotel);
						break;
					case R.id.more_cooking_school:
						Utils.log("============7=========");
						Intent cook = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cook.ac.kr/"));
						startActivity(cook);
						break;
					case R.id.more_Beauty_School:
						Utils.log("============8=========");
						Intent beautyart = new Intent(Intent.ACTION_VIEW, Uri.parse("http://beautyart.ac.kr/"));
						startActivity(beautyart);
						break;
					default:

						break;
					}

				}
			});
		}
	}
	
	public void textViewInit(int []resourceIdx){
		for (int i = 0; i < resourceIdx.length; i++) {

			final int resource = resourceIdx[i];
			TextView textView=(TextView)findViewById(resource);
			textView.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					switch (resource) {
					case R.id.map_textView_bt:
						Utils.changeActivity(More.this, MoreGloriaMapPosition.class);
						break;
					case R.id.gloria_textView_bt:
						Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cyber.gloriahrd.com/"));
						startActivity(intent);
						break;
					case R.id.bookcafeWeb_textView_bt:
						Intent book = new Intent(Intent.ACTION_VIEW, Uri.parse("http://book.gloriahrd.com/"));
						startActivity(book);
						break;
					case R.id.Employment_textView_bt:
						Intent job = new Intent(Intent.ACTION_VIEW, Uri.parse("http://job.kac.ac.kr/"));
						startActivity(job);
						break;
					case R.id.air_textView_bt:
						Intent kac = new Intent(Intent.ACTION_VIEW, Uri.parse("http://kac.ac.kr/"));
						startActivity(kac);
						break;
					case R.id.hotel_textView_bt:
						Intent hotel = new Intent(Intent.ACTION_VIEW, Uri.parse("http://hotel.ac.kr/"));
						startActivity(hotel);
						break;
					case R.id.cooking_textView_bt:
						Intent cook = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cook.ac.kr/"));
						startActivity(cook);
						break;
					case R.id.Beauty_textView_bt:
						Intent beautyart = new Intent(Intent.ACTION_VIEW, Uri.parse("http://beautyart.ac.kr/"));
						startActivity(beautyart);
						break;
					default:
						break;
					}
					
				}
			});
		}
	}
	
	/**
	 * 현재 Logout Button 누르면 기존 LogIn 정보는 전부 초기화된다 완전 빈값 
	 * 전체 Activity 를  모두  종료하고 맨 초기 진입부인 Login 창으로 돌아간다.
	 * 근소한 차이지만 성능이 낮은 단말을 위해서 UI thread 갱신 추가 하였다.
	 * Thread 내부에 동작들을 모두 넣어서 사용한다.
	 */
	public void allClearActivityAndReturnBack(){
		
		Utils.setPreference(More.this, Constants.PRE_STRING_LOGIN_SUCCESS, "");
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				allClearActivity();
				Intent i = new Intent(More.this, LoginActivity.class ).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
				finish();
			}
		}).start();
	}
	/**
	 * 종료와 동시에 logout 도 모두 한다.
	 */
	@Override
	public void onBackPressed() {
		Utils.showConfirmDialog(More.this, "종료", "글로리아 모바일을 종료 하시겠습니까?",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						allClearActivity();

					}
				}, null);
	}
}
